import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_widgets/widgets/signaturePad/kq_signature_pad.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

class SignaturePadDemo extends StatefulWidget {
  const SignaturePadDemo({super.key});

  @override
  State<StatefulWidget> createState() => SignaturePadDemoState();
}

class SignaturePadDemoState extends State<SignaturePadDemo> {
  final GlobalKey<KqSignaturePadState> keyKqSignaturePad =
      GlobalKey<KqSignaturePadState>();

  String? imgPath;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '手写签名',
        actions: KqInkWell(
          verticalPadding: 10.r,
          radius: 4.r,
          onTap: () {
            keyKqSignaturePad.currentState!.getPicture().then((value) => {
                  setState(() {
                    imgPath = value;
                  })
                });
          },
          child: Text(
            '截图',
            style: TextStyle(
              color: Colors.white,
              fontSize: 16.sp,
            ),
          ),
        ),
        back: () {
          Get.back();
        },
      ),
      body: Column(
        children: [
          Container(
            width: context.width,
            height: 400.r,
            child: KqSignaturePad(
              key: keyKqSignaturePad,
              backgroundColor: Colors.blue,
            ),
          ),
          KqImage.file(url: imgPath ?? "",height: 200.r,fit: BoxFit.fill,)
        ],
      ),
    );
  }
}
